﻿Public Class CLSCestaProdutos
    Dim sql As String
    Dim objbanco As New CLSBanco

    Dim CP_idCesta As Integer
    Dim CP_idPro As Long
    Dim CP_qtd As Integer



    Public Property idCesta() As Integer
        Get
            Return CP_idCesta
        End Get
        Set(ByVal value As Integer)
            CP_idCesta = value
        End Set
    End Property

    Public Property idProduto() As Long
        Get
            Return CP_idPro
        End Get
        Set(ByVal value As Long)
            CP_idPro = value
        End Set
    End Property

    Public Property qtdCestas() As Integer
        Get
            Return CP_qtd
        End Get
        Set(ByVal value As Integer)
            CP_qtd = value
        End Set
    End Property



    Public Sub Gravar()

        Try

            sql = "insert into CestaProdutos " & _
              "(CP_idCesta" & _
              ",CP_idPro" & _
              ",CP_qtd" & _
              ") values " & _
              "(" & CP_idCesta & _
              "," & CP_idPro & _
              "," & CP_qtd & _
              ")"

            objbanco.executar_comando(sql)


        Catch ex As Exception
            MsgBox("Ocorreu o erro: " & ex.Message, MsgBoxStyle.Critical)
            objbanco.fechar_banco()
        End Try
    End Sub

    Public Function LocalizarPorNome(ByVal NomeCesta As String) As DataTable
        sql = "select * from Cestas where Ces_Nom like '" & NomeCesta & "%'"
        Dim objda As New OleDb.OleDbDataAdapter(sql, objbanco.objcon)
        Dim objds As New DataSet
        objda.Fill(objds)
        Return objds.Tables(0)
    End Function

    Public Function LocalizarPorID(ByVal digiteID As Integer) As DataTable
        sql = "select * from Cestas where Ces_ID = " & digiteID
        Dim objda As New OleDb.OleDbDataAdapter(sql, objbanco.objcon)
        Dim objds As New DataSet
        objda.Fill(objds)
        Return objds.Tables(0)
    End Function
End Class
